<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/myconfig/layui/css/layui.css}" media="all">
    <link rel="stylesheet" href="../static/myconfig/layui/css/layui.css" media="all">
    <style>
        body{margin: 20px 20px 20px 0;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="updateForm">
    <input type="hidden" name="enterpriceId" value="">
    <div class="layui-form-item">
        <label class="layui-form-label">企业名称</label>
        <div class="layui-input-block">
            <input type="text" name="enterpriceName" lay-verify="required" placeholder="请输入项目名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业负责人</label>
        <div class="layui-input-block">
            <input type="text" name="enterpricePrincipal" lay-verify="required" placeholder="请输入项目名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业地址</label>
        <div class="layui-input-block">
            <input type="text" name="enterpriceAddress" lay-verify="required" placeholder="请输入项目名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">企业简介</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入企业简介" class="layui-textarea" lay-verify="required" name="enterpriceInformation"></textarea>
        </div>
    </div>

    <div class="layui-form-item" style="margin-top: 10px;">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script th:src="@{/myconfig/layui/layui.js}"></script>
<script src="../static/myconfig/layui/layui.js"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,$ = layui.$;

        var checkStatus = parent.businessProjectId;

        console.log(checkStatus);
        //日期
        laydate.render({
            elem: '#date'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function(value) {
                if (value.length == 0) {
                    return '企业名不能位空';
                }
            }
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            var enterprice = data.field;
            $.ajax({
                url:'goodEnterprise/update'
                ,data:enterprice
                ,success:function (result) {
                    if (result.code == 200){
                        layer.msg("更新成功",{
                            icon:6
                        })
                        setTimeout("freshClose()",1000);
                    } else{
                        layer.msg("更新失败"),{
                            icon:5
                        }
                    }
                }
            })
            return false;
        });

    });

    function init(enterpriceId) {
        layui.use(['form', 'layedit', 'laydate'], function(){
            var form = layui.form,
                $ = layui.$;

            $.ajax({
                url:'goodEnterprise/initForm'
                ,data:{enterpriceId:enterpriceId}
                ,success:function (result) {
                    form.val('updateForm',{
                        "enterpriceId":enterpriceId
                        ,"enterpriceName":result.data.enterpriceName
                        ,"enterpriceInformation":result.data.enterpriceInformation
                        ,"enterpriceAddress":result.data.enterpriceAddress
                        ,"enterpricePrincipal":result.data.enterpricePrincipal
                    })
                }
            })
        })
    }
    function freshClose(){
        window.parent.location.reload();//刷新父页面
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index)
    }
</script>
</body>
</html>